
class my_scoreboard extends uvm_scoreboard;
  my_transaction_code  expect_queue[$];

  // uvm_blocking_get_port #(my_transaction)  exp_port;
  // uvm_blocking_get_port #(my_transaction)  act_port;
  uvm_blocking_put_imp#(my_transaction_code, my_scoreboard) code_from_model;
  uvm_blocking_get_port#(my_transaction_code) code_from_dut;

  

  `uvm_component_utils(my_scoreboard)

  extern function new(string name, uvm_component parent = null);
  extern virtual function void build_phase(uvm_phase phase);
  extern virtual task main_phase(uvm_phase phase);
  extern virtual function put(my_transaction_code tr);

  

endclass



function my_scoreboard::put(my_transaction_code tr);
  //my_transaction_code tr_tmp;

  `uvm_info("my_scoreboard", "my_scoreboard get code from model", UVM_LOW);

  if(tr == null)
    `uvm_error("my_scoreboard", "put is empty");

  expect_queue.push_back(tr);

endfunction

function my_scoreboard::new(string name, uvm_component parent = null);
  super.new(name, parent);
endfunction

function void my_scoreboard::build_phase(uvm_phase phase);
  super.build_phase(phase);

  code_from_model = new("code_from_model", this);
  code_from_dut = new("code_from_dut", this);
endfunction

task my_scoreboard::main_phase(uvm_phase phase);

my_transaction_code dut_code;
  my_transaction_code queue_code;
  

  super.main_phase(phase);

  

  while(1) begin
    code_from_dut.get(dut_code);

    `uvm_info("my_scoreboard", "my_scoreboard working", UVM_LOW);
      if(dut_code == null)
        `uvm_error("my_scoreboard", "Received from DUT is empty");

    //判断队列
    if(expect_queue.size() == 0)begin
      `uvm_error("my_scoreboard", "Received from DUT, while Expect Queue is empty");
    end
    else begin
      //$display("size %d", expect_queue.size());

      //出队列
      queue_code = expect_queue.pop_front();
      if(queue_code == null)
        `uvm_error("my_scoreboard", "Received from queue_code is empty");

      //判断是否正确
      if(queue_code.polar_enc_data_out == dut_code.polar_enc_data_out)begin
        $display("encoder correct");
      end
      else begin
        $display("encoder error");

        $display("model code %h",queue_code.polar_enc_data_out);
        $display("dut code %h",dut_code.polar_enc_data_out);
      end
      
    end
  end

endtask